#![no_std]
#![no_main]

#[macro_use]
extern crate unistd;

#[global_allocator]
static GLOBAL_ALLOCATOR: linked_list_allocator::LockedHeap =
    linked_list_allocator::LockedHeap::empty();

const HEAP_SIZE: usize = 8 * 1024;

#[unsafe(no_mangle)]
extern "C" fn _start(
    acpi_addr: usize,
    fb_addr: usize,
    magic1: usize,
    magic2: usize,
    magic3: usize,
    magic4: usize,
) -> ! {
    let heap_start = unistd::mm::mmap(0, HEAP_SIZE, 0, 0x87);
    unsafe {
        GLOBAL_ALLOCATOR
            .lock()
            .init(heap_start as *mut u8, HEAP_SIZE);
    }

    println!("acpi_addr: {:#X}", acpi_addr);
    println!("fb_addr: {:#X}", fb_addr);

    assert!(magic1 == 0x1);
    assert!(magic2 == 0x2);
    assert!(magic3 == 0x3);
    assert!(magic4 == 0x4);

    unistd::module::load_module("usr/drvd", Some((acpi_addr, fb_addr, 0, 0, 0, 0)));

    unistd::proc::exit(0)
}

#[panic_handler]
fn panic(info: &core::panic::PanicInfo) -> ! {
    println!("{}", info);
    unistd::proc::exit(1)
}
